package LeetCode.month04.day95;

import java.util.PriorityQueue;

/**
 * @author 16778
 * @date 2025/11/4 10:50
 * @description
 */
public class No295 {
}

class MedianFinder {
    PriorityQueue<Integer> left = new PriorityQueue<>((a, b) -> b - a);
    PriorityQueue<Integer> right = new PriorityQueue<>((a, b)->a-b);

    public MedianFinder() {

    }

    public void addNum(int num) {
        if(left.size()==right.size()){
            right.offer(num);
            left.offer(right.poll());
        }else{
            left.offer(num);
            right.offer(left.poll());
        }
    }

    public double findMedian() {
        if(left.size()==right.size()){
            return (left.peek()+right.peek())/2.0;
        }else{
            return left.peek();
        }
    }
}
